<template>
    <div class="wrapper">
        <div class="top">选择活动</div>
        <div class="list" v-for="(item, index) in activeList" :key="index" @click="clickActive(item.name)">
            <div>
                {{ item.name }}
            </div>
            <img v-show="actId === item.name" src="@/assets/selected.png"/>
        </div>
        <div class="confirm" @click="confirm">确认</div>
    </div>
</template>
<script>
import {findByTargetAndClassesId, posDepositConfig, posMarketingChange} from '@/api/posManagement.ts'
import {showDialog} from 'vant'
import store from '../../store'

export default {
    data() {
        return {
            activeList: [], // 活动列表
            checkedArr: [], // 选择的终端列表
            myInfo: store.state.user.userInfo.agentBean,

            actId: ''
        }
    },
    created() {
        console.log(this.myInfo)
    },
    methods: {
        clickActive(actCode) {
            this.actId = actCode
        },
        confirm() {
            if (this.$route.query.agencySource === 'HLB' || this.$route.query.agencySource === 'UEN' || this.$route.query.agencySource === 'QB') {
                posDepositConfig({
                    posSns: store.state.data.POSTUSN,
                    agencySource: this.$route.query.agencySource,
                    actCode: this.actId
                }).then(res => {
                    showDialog({
                        message: '更改成功',
                        title: '提示'
                    }).then(() => {
                        this.$router.go(-1)
                    })
                })
            }
            if (this.$route.query.agencySource === 'LS' ) {
                posMarketingChange({
                    posSns: store.state.data.POSTUSN,
                    agencySource: this.$route.query.agencySource,
                    actCode: this.actId,
                    classesId: this.myInfo.classesId
                }).then(res => {
                    showDialog({
                        message: '更改成功',
                        title: '提示'
                    }).then(() => {
                        this.$router.go(-1)
                    })
                })
            }
        }
    },

    mounted() {

        console.log(this.$route)


        findByTargetAndClassesId({
            agencySource: this.$route.query.agencySource
        }).then(res => {
            this.activeList = res.object
            // for (var i = 0; i < this.activeList.length; i++) {
            //     if (this.activeList[i].deposit === 0) {
            //         this.activeList.splice(i, 1) //删除下标为i 的元素，i开始只删除一个就它自己了
            //         i-- //删除一个元素后数组长度减一了
            //     }
            // }
        })
    }
}
</script>

<style lang="scss" scoped>
.wrapper {
    padding: 20px 11px 0;
    background-color: #f5f5f5;
}

.top {
    font-size: 18px;
    font-weight: 400;
    color: #000000;
}

.list {
    padding: 10px 20px;
    margin-top: 15px;
    border-radius: 10px;
    font-size: 16px;
    //font-family: Microsoft YaHei-Regular, Microsoft YaHei;
    font-weight: 400;
    background: #fff;
    color: #545454;
    display: flex;
    align-items: center;
    justify-content: space-between;

    img {
        height: 20px;
        width: 20px;
    }
}

.confirm {
    width: 160px;
    height: 40px;
    background: #66d6ff;
    border-radius: 7px;
    font-size: 14px;
    //font-family: Microsoft YaHei-Regular, Microsoft YaHei;
    font-weight: 400;
    color: #ffffff;
    margin: 100px auto 0;
    text-align: center;
    line-height: 40px;
}
</style>
